﻿using System;

namespace SpaceGame.Gameplay
{
    /// <summary>
    /// Class responsbile for creating asteroids and spawning them.
    /// </summary>
    static class AsteroidFactory
    {
        static readonly Random random = new Random();

        /// <summary>
        /// Define factors for small, medium and large.
        /// </summary>
        private readonly static float[,] radiusFactor = new float[3,2] {{8, 16}, {24,16}, {32,64}};

        /// <summary>
        /// Create many asteroids and add them to the game world.
        /// </summary>
        /// <param name="world">world to add asteroids</param>
        /// <param name="density">specify amount and type of asteroids</param>
        public static void SpawnAsteroids(World world, AsteroidDensity density)
        {
            switch (density)
            {
                case AsteroidDensity.None:
                    break;
                case AsteroidDensity.Low:
                    SpawnAsteroids(world, 4, 3, 0);
                    break;
                case AsteroidDensity.Medium:
                    SpawnAsteroids(world, 6, 4, 1);
                    break;
                case AsteroidDensity.High:
                    SpawnAsteroids(world, 8, 6, 2);
                    break;
            }
        }

         /// <summary>
        /// Create many asteroids and add them to the game world.
        /// </summary>
        /// <param name="world">world asteroids will be spawn</param>
        /// <param name="amount">Amount for each of small, medium and large</param>
        private static void SpawnAsteroids(World world, params int[] amount)
        {
            for (int i = 0; i < radiusFactor.GetLength(0); i++ )
            {
                for(int j=0; j < amount[i]; j++)
                {
                    var radius = radiusFactor[i,0] + radiusFactor[i,1] * (float)random.NextDouble();
                    Asteroid asteroid = new Asteroid(world, radius);
                    asteroid.Spawn(true);
                }
            } 
        }

    }
}
